package club.emergency.wechat.aliyun_sms.consumer.service.fallback_factory;

import club.emergency.wechat.aliyun_sms.consumer.service.SendMessageConsumer;
import club.emergency.wechat.common.response.ResponseEntity;
import club.emergency.wechat.common.response.StatusCode;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * Create with IntelliJ IDEA
 * Project Name: wechat
 * Package Name: club.emergency.wechat.aliyun_sms.consumer.service.fallback_factory
 * Date: 2019/3/25
 *
 * @author: 快乐的小菌菌
 * Description:
 */
@Component
public class SendMessageFallbackFactory implements FallbackFactory<SendMessageConsumer> {
    @Override
    public SendMessageConsumer create(Throwable throwable) {
        return new SendMessageConsumer() {
            @Override
            public String sendSms(String phoneNumber, Map<String, Object> paramMap) {
                return ResponseEntity.error(StatusCode.SEND_SMS_ERROR, "发送信息失败！", throwable.getMessage());
            }

            @Override
            public String sendVerificationSms(String phoneNumber) {
                return ResponseEntity.error(StatusCode.SEND_SMS_ERROR, "发送信息失败！", throwable.getMessage());
            }

            @Override
            public String confirmVerification(String phoneNumber, String confirmCode) {
                return ResponseEntity.error(StatusCode.REDIS_GET_ERROR, "获取对应的手机对应的验证码失败！", throwable.getMessage());
            }
        };
    }
}
